<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String ctxPath = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ ctxPath + "/";
	String SYSTEM_NAME = "EZMES";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><%=SYSTEM_NAME%></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<base id="baseUrl" href="<%=basePath%>" />
<link href="<%=basePath%>css/bootstrap.min.css?v=3.4.0"
	rel="stylesheet">
<link href="<%=basePath%>css/font-awesome.min.css?v=4.3.0"
	rel="stylesheet">

<!-- Data Tables -->
<link href="<%=basePath%>css/animate.min.css" rel="stylesheet">
<link href="<%=basePath%>css/style.min.css?v=3.0.0" rel="stylesheet">
</head>
<body style="background: #e7e8eb">
<form action="news/add_news" id="formId" method="post" enctype="multipart/form-data">
	<div class="container-fluid"
		style="margin: 30px;border:1px solid #d9dadc;">
		<div class="row" style="border-bottom: 1px solid #d9dadc;">
			<div class="col-md-12" style="margin: 10px">返回列表/添加新闻</div>
		</div>
		<div class="row" style="border-bottom: 1px solid #d9dadc;">
			<div class="col-md-2">
				<div style="padding-left: 10px">
				<img id="preview" src="" width="100" height="100" style="display: block;border: 1px solid blue;" />
				<div>
					<span>轮播图：640*280</span>
				</div>
				<div><span>标题图：45*45</span></div>
				<input type="file" name="file" id="doc" multiple="multiple" style="width:150px;" onchange="javascript:setImagePreview();">
				</div>
			</div>
			<div class="col-md-10">
				<div class="form-group" style="padding: 20px">
					<label class="col-sm-2 control-label">新闻标题：</label>
					<div class="col-sm-10">
						<input type="text" name="news.n_title" class="form-control"
							required="" placeholder="请输入新闻标题" style="font-family: 黑体;font-size:20px">
					</div>
				</div>
				<div class="form-group" style="padding: 20px">
					<label class="col-sm-2 control-label">作者：</label>
					<div class="col-sm-10">
						<input type="text" disabled="true" class="form-control"
							 placeholder="请输入作者名称" value="${sessionUser.userName}">
						<input type="hidden" value="${sessionUser.userId}" name="news.n_author">	 
					</div>
				</div>
				<div class="form-group" style="padding: 20px">
					<label class="col-sm-2 control-label">新闻类别：</label>
					<div class="col-sm-10">
						<select class="form-control" required="" name="news.nt_id">
							<option value="">请选择</option>
							<c:forEach items="${nts}" var="nt">
								<option value="${nt.nt_id}">${nt.nt_name}</option>
            				</c:forEach>
						</select>
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="border-bottom: 1px solid #d9dadc;">
			<div class="col-md-12" style="margin: 10px">
				<script id="container" name="news.n_content" type="text/plain"></script>
			</div>
		</div>
	</div>
	<div class="navbar-fixed-bottom">
		<div class="col-md-12" style="text-align: center; margin-bottom: 10px">
			<button type="submit" class="btn btn-primary">
				<i class="fa fa-check"></i> 保存
			</button>
			<button type="submit" class="btn btn-primary" onclick="updateFormAction()">
				<i class="fa fa-cloud-upload"></i> 保存并发布
			</button>
			<button type="button" onclick="houtui()"  class="btn btn-primary">
				<i class="fa fa-reply"></i> 取消
			</button>
		</div>
	</div>
	</form>
<body>




	<!-- 全局js -->
	<script src="<%=basePath%>js/jquery-2.1.1.min.js"></script>
	<script src="<%=basePath%>js/bootstrap.min.js?v=3.4.0"></script>
	<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>js/plugins/ueditor1_4_3_2-utf8-jsp/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>js/plugins/ueditor1_4_3_2-utf8-jsp/utf8-jsp/ueditor.all.min.js">
		
	</script>
	<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
	<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
	<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>js/plugins/ueditor1_4_3_2-utf8-jsp/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script src="<%=basePath %>js/plugins/layer/layer.js"></script>
	<!-- 自定义js -->
	<script src="<%=basePath%>js/content.min.js?v=1.0.0"></script>
</body>
<script type="text/javascript">
	$(function() {
		var ue = UE.getEditor('container');
	});
	//下面用于图片上传预览功能
	function setImagePreview(avalue) {
		//input
		var docObj = document.getElementById("doc");
		//img
		var imgObjPreview = document.getElementById("preview");
		//div
		var divs = document.getElementById("localImag");
		if (docObj.files && docObj.files[0]) {
			//火狐下，直接设img属性
			imgObjPreview.style.display = 'block';
			imgObjPreview.style.width = '100px';
			imgObjPreview.style.height = '100px';
			//imgObjPreview.src = docObj.files[0].getAsDataURL();
			//火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
			imgObjPreview.src = window.URL.createObjectURL(docObj.files[0]);
		} else {
			//IE下，使用滤镜
			docObj.select();
			var imgSrc = document.selection.createRange().text;
			var localImagId = document.getElementById("localImag");
			//必须设置初始大小
			localImagId.style.width = "100px";
			localImagId.style.height = "100px";
			//图片异常的捕捉，防止用户修改后缀来伪造图片
			try {
				localImagId.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
				localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
			} catch (e) {
				alert("您上传的图片格式不正确，请重新选择!");
				return false;
			}
			imgObjPreview.style.display = 'none';
			document.selection.empty();
		}
		return true;
	}
	function houtui(){
		layer.confirm('您确定要取消？', {
			  btn: ['确定','不确定'] //按钮
			}, function(){
				window.history.back();
			}, function(index){
				layer.close(index);
			});
	}
	function updateFormAction(){
		$("#formId").attr("action","news/add_release_news")
	}
</script>
</html>
